package com.abigdreamer.im.server.ui.desktop.internal;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class JavaVM {

	private String java_version;					//Java 运行时环境版本
	private String java_vendor;						//Java 运行时环境供应商
	private String java_vendor_url;					//Java 供应商的 URL
	private String java_home;						//Java 安装目录
	private String java_vm_specification_version;	//Java 虚拟机规范版本
	private String java_vm_specification_vendor;    //Java 虚拟机规范供应商
	private String java_vm_specification_name;		//Java 虚拟机规范名称
	private String java_vm_version;					//Java 虚拟机实现版本
	private String java_vm_vendor;					//Java 虚拟机实现供应商
	private String java_vm_name;					//Java 虚拟机实现名称
	private String java_specification_version;		//Java 运行时环境规范版本
	private String java_specification_vendor;	    //Java 运行时环境规范供应商
	private String java_specification_name;			//Java 运行时环境规范名称
	private String java_class_version;				//Java 类格式版本号
	private String java_class_path;				    //Java 类路径
	private String java_library_path;				//加载库时搜索的路径列表
	private String java_io_tmpdir;					//默认的临时文件路径
	private String java_compiler;	                //要使用的 JIT 编译器的名称
	private String java_ext_dirs;					//一个或多个扩展目录的路径
	private String os_name;							//操作系统的名称
	private String os_arch;							//操作系统的架构
	private String os_version;						//操作系统的版本
	private String file_separator;					//文件分隔符（在 UNIX 系统中是“/”）
	private String path_separator;					//路径分隔符（在 UNIX 系统中是“:”）
	private String line_separator;					//行分隔符（在 UNIX 系统中是“/n”）
	private String user_name;						//用户的账户名称
	private String user_home;						//用户的主目录
	private String user_dir;						//用户的当前工作目录
	private String sun_os_patch_level;              //得到操作系统版本
	private String sun_cpu_isalist;                 //得到CPU系统信息
	
	
	public String getJava_version() {
		return java_version;
	}
	public void setJava_version(String java_version) {
		this.java_version = java_version;
	}
	public String getJava_vendor() {
		return java_vendor;
	}
	public void setJava_vendor(String java_vendor) {
		this.java_vendor = java_vendor;
	}
	public String getJava_vendor_url() {
		return java_vendor_url;
	}
	public void setJava_vendor_url(String java_vendor_url) {
		this.java_vendor_url = java_vendor_url;
	}
	public String getJava_home() {
		return java_home;
	}
	public void setJava_home(String java_home) {
		this.java_home = java_home;
	}
	public String getJava_vm_specification_version() {
		return java_vm_specification_version;
	}
	public void setJava_vm_specification_version(
			String java_vm_specification_version) {
		this.java_vm_specification_version = java_vm_specification_version;
	}
	public String getJava_vm_specification_vendor() {
		return java_vm_specification_vendor;
	}
	public void setJava_vm_specification_vendor(String java_vm_specification_vendor) {
		this.java_vm_specification_vendor = java_vm_specification_vendor;
	}
	public String getJava_vm_specification_name() {
		return java_vm_specification_name;
	}
	public void setJava_vm_specification_name(String java_vm_specification_name) {
		this.java_vm_specification_name = java_vm_specification_name;
	}
	public String getJava_vm_version() {
		return java_vm_version;
	}
	public void setJava_vm_version(String java_vm_version) {
		this.java_vm_version = java_vm_version;
	}
	public String getJava_vm_vendor() {
		return java_vm_vendor;
	}
	public void setJava_vm_vendor(String java_vm_vendor) {
		this.java_vm_vendor = java_vm_vendor;
	}
	public String getJava_vm_name() {
		return java_vm_name;
	}
	public void setJava_vm_name(String java_vm_name) {
		this.java_vm_name = java_vm_name;
	}
	public String getJava_specification_version() {
		return java_specification_version;
	}
	public void setJava_specification_version(String java_specification_version) {
		this.java_specification_version = java_specification_version;
	}
	public String getJava_specification_vendor() {
		return java_specification_vendor;
	}
	public void setJava_specification_vendor(String java_specification_vendor) {
		this.java_specification_vendor = java_specification_vendor;
	}
	public String getJava_specification_name() {
		return java_specification_name;
	}
	public void setJava_specification_name(String java_specification_name) {
		this.java_specification_name = java_specification_name;
	}
	public String getJava_class_version() {
		return java_class_version;
	}
	public void setJava_class_version(String java_class_version) {
		this.java_class_version = java_class_version;
	}
	public String getJava_class_path() {
		return java_class_path;
	}
	public void setJava_class_path(String java_class_path) {
		this.java_class_path = java_class_path;
	}
	public String getJava_library_path() {
		return java_library_path;
	}
	public void setJava_library_path(String java_library_path) {
		this.java_library_path = java_library_path;
	}
	public String getJava_io_tmpdir() {
		return java_io_tmpdir;
	}
	public void setJava_io_tmpdir(String java_io_tmpdir) {
		this.java_io_tmpdir = java_io_tmpdir;
	}
	public String getJava_compiler() {
		return java_compiler;
	}
	public void setJava_compiler(String java_compiler) {
		this.java_compiler = java_compiler;
	}
	public String getJava_ext_dirs() {
		return java_ext_dirs;
	}
	public void setJava_ext_dirs(String java_ext_dirs) {
		this.java_ext_dirs = java_ext_dirs;
	}
	public String getOs_name() {
		return os_name;
	}
	public void setOs_name(String os_name) {
		this.os_name = os_name;
	}
	public String getOs_arch() {
		return os_arch;
	}
	public void setOs_arch(String os_arch) {
		this.os_arch = os_arch;
	}
	public String getOs_version() {
		return os_version;
	}
	public void setOs_version(String os_version) {
		this.os_version = os_version;
	}
	public String getFile_separator() {
		return file_separator;
	}
	public void setFile_separator(String file_separator) {
		this.file_separator = file_separator;
	}
	public String getPath_separator() {
		return path_separator;
	}
	public void setPath_separator(String path_separator) {
		this.path_separator = path_separator;
	}
	public String getLine_separator() {
		return line_separator;
	}
	public void setLine_separator(String line_separator) {
		this.line_separator = line_separator;
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	public String getUser_home() {
		return user_home;
	}
	public void setUser_home(String user_home) {
		this.user_home = user_home;
	}
	public String getUser_dir() {
		return user_dir;
	}
	public void setUser_dir(String user_dir) {
		this.user_dir = user_dir;
	}
	public String getSun_os_patch_level() {
		return sun_os_patch_level;
	}
	public void setSun_os_patch_level(String sun_os_patch_level) {
		this.sun_os_patch_level = sun_os_patch_level;
	}
	public String getSun_cpu_isalist() {
		return sun_cpu_isalist;
	}
	public void setSun_cpu_isalist(String sun_cpu_isalist) {
		this.sun_cpu_isalist = sun_cpu_isalist;
	}
	

	public static List<PropertyBean> getAllPropetys(){
		List<PropertyBean> Propertys=new ArrayList<PropertyBean>();
		Class<JavaVM> clazz =JavaVM.class;
		Field[] fields = clazz.getDeclaredFields();
		for(Field field:fields){
			    String fieldName=field.getName().toLowerCase();
			    fieldName=fieldName.replace("_", ".");
				String value=System.getProperty(fieldName);
				PropertyBean property=new PropertyBean();
				property.setValue(value);
				property.setName(fieldName);
				Propertys.add(property);
			}
		
		return Propertys;
		}
		
	
	public static JavaVM getJavaVM() throws Exception{
		Class<JavaVM> clazz =JavaVM.class;
		JavaVM javaVm=new JavaVM();
		Method[] methods = clazz.getDeclaredMethods();
		for(Method method:methods){
			String methodName=method.getName().toLowerCase();
			if(methodName.contains("set")){
				String methodShortName=methodName.substring(3).replace("_", ".");
				String value=System.getProperty(methodShortName);
				method.invoke(javaVm,value);
			}
		}
		return javaVm;
	}
}

class PropertyBean {

	private String name;
	private String value;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	
	public String toString(){
		StringBuffer buffer=new StringBuffer();
		buffer.append(name+"值为:"+value);
		return buffer.toString();
	}
}